import {request} from "../../request/index"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperList: [],
    catesList: [],
    floorList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   success: (result)=>{
    //     console.log(result);
    //     this.setData({
    //       swiperList:result.data.message
    //     })
    //   }
    // });
    // console.log(floorList);
    this.getSwiperImage()
    this.getCateList()
    this.getFloorList()
  },

  getSwiperImage() {
    //轮播图片
    request({url: '/home/swiperdata'})
    .then(result => {
      this.setData({
        swiperList:result
      })
    })
  },

  getCateList() {
    //导航信息
    request({url: '/home/catitems'})
    .then(result => {
      this.setData({
        catesList:result
      })
    })
  },

  //楼层数据
  getFloorList() {
    request({url: '/home/floordata'})
    .then(result => {
      result.forEach(v1 => {
        v1.product_list.forEach(v2 => {
          v2.navigator_url = v2.navigator_url.replace(/\?/,'/index\?')
          console.log(v2.navigator_url);
        })
      })
      this.setData({
        floorList:result
      })
    })
  }
  
})

